package com.woniu.user.mqlistener;

import com.woniu.user.model.Order;
import com.woniu.user.model.OrderLog;
import com.woniu.user.service.OrderLogService;
import com.woniu.user.service.dto.OrderDto;
import com.woniu.user.util.BeanCopyUtil;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.time.LocalDateTime;

@Component
@RocketMQMessageListener(topic = "order-topic", consumerGroup = "order-group")
public class OrderLitener implements RocketMQListener<OrderDto> {

    @Resource
    private OrderLogService orderLogService;

    @Override
    public void onMessage(OrderDto orderDto) {
        OrderLog orderLog = BeanCopyUtil.copyObject(orderDto, OrderLog.class);
        orderLog.setLogTime(LocalDateTime.now());
        orderLogService.save(orderLog);
    }
}
